package com.ccrfid.rmc6.resource.device.pojo;

import com.ccrfid.rmc6.util.JsonUtil;

import java.util.List;
import java.util.Set;

public class MessageBody {
    private Set<String> macs;
    private Integer bufferSize = 200;
    private Integer timeout = 5;
    private List<Integer> value;

    public MessageBody() {
    }

    public MessageBody(Integer timeout) {
        this.timeout = timeout;
    }

    public Set<String> getMacs() {
        return macs;
    }

    public void setMacs(Set<String> macs) {
        this.macs = macs;
    }

    public Integer getBufferSize() {
        return bufferSize;
    }

    public void setBufferSize(Integer bufferSize) {
        this.bufferSize = bufferSize;
    }

    public Integer getTimeout() {
        return timeout;
    }

    public void setTimeout(Integer timeout) {
        this.timeout = timeout;
    }

    public List<Integer> getValue() {
        return value;
    }

    public void setValue(List<Integer> value) {
        this.value = value;
    }

    public void updateSeq(int seq) {
        Integer cmd = value.get(0);
        if (cmd.equals(0x0F)) {
            value.set(1, seq & 0xFF);
        } else {
            int seq1 = (seq >>> 8) & 0xFF;
            int seq2 = seq & 0xFF;
            value.set(1, seq1);
            value.set(2, seq2);
        }
    }

    @Override
    public String toString() {
        return JsonUtil.INSTANCE.writeValueAsString(this);
    }
}
